<template>
  <page-layout>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div>
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input style="width:100%;" placeholder="请输入客户名称" v-model="queryParam.customerName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item>
              <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </a-form-item>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <vxe-grid
        id="CrmCustomerPublicList"
        keep-source
        ref="vxeTable"
        :height="null"
        v-bind="options"
        @checkbox-change="onSelectChange"
        @checkbox-all="onSelectChange"
        @page-change="handlePageChange"
      >
      <template #action="{ row }">
        <template>
          <a @click="handleEdit(row)" >编辑</a>
          <a-divider type="vertical" />
          <a @click="showFollowup(row)">跟进记录</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(row)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleDealStatus(row)">变更成交状态</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </template>
    </vxe-grid>
    </div>
    <!-- table区域-end -->
    <CrmCustomerModal ref="modalForm" @ok="modalFormOk"></CrmCustomerModal>
    <CrmCustomerDetail ref="detailForm" @ok="modalFormOk"></CrmCustomerDetail>
    <!-- 跟进记录功能 -->
    <crm-followup ref="followupForm" @ok="modalFormOk"></crm-followup>
  </a-card>
  </page-layout>
</template>

<script>
import PageLayout from '@/layouts/PageLayout'
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import { deleteAction } from '@/services/manage'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import CrmCustomerModal from './modules/CrmCustomerModal.vue'
import CrmCustomerDetail from './modules/CrmCustomerDetail.vue'
import CrmFollowup from "../followup/CrmFollowup";

export default {
  name: 'CrmCustomerList',
  components: {
    PageLayout,
    ZDictSelectTag,
    CrmCustomerModal,
    CrmCustomerDetail,
    CrmFollowup
  },
  mixins: [VxeTableMixin],
  data() {
    return {
      customTableToolbar: {
        buttons: []
      },
      columns: [
          {
            title:'客户名称',
            width:300,
            align:"center",
            field: 'customerName'
          },
          {
            title:'客户归属人',
            align:"center",
            field: 'belongTo',
            width:300,
          },
          {
            title:'客户联系方式',
            align:"center",
            field: 'contactsInfo',
            width:300,
          },
          {
            title:'最新活动记录时间',
            align:"center",
            field: 'lastTime',
            width:300
          },
          // {
          //   title: '操作',
          //   field: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:200,
          //   slots: { default: 'action' }
          // }
        ],
      url: {
        list: "/customer/crmCustomer/public/list",
      },
      // 查询参数
      queryParam: {},
      selectedRowKeys: [],
      selectedRows: [],
      toggleSearchStatus: false
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    handleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { "id": id }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    showDetail(record){
      this.$refs.detailForm.open(record);
    },
    //跟进记录功能 ，自行修改category为自己的表名
    showFollowup(record){
      let category = 'crm_customer';
      this.$refs.followupForm.open(record,category);
    },
  }
}
</script>

